import $ from "jquery";
import {url} from "../../util/config";
import {message} from "antd";
import login from "../login";
function getNewLogin(searchKey=null,startDate=null,endDate=null,current=null,pageSize=null) {
    return getNotice(searchKey,startDate,endDate,current,pageSize)
}
export default function getNotice(searchKey=null,startDate=null,endDate=null,current=null,pageSize=null) {
    let notices = [];
    let token = localStorage.getItem("token")
    let status = {
        data:null,
        count:null
    }
    $.ajax({
        async:false,
        headers: {
            'Accept': "application/json",
            'Authorization': token
        },
        url: url.api_url+`Notice/GetNoticeList?searchKey=${searchKey}&startDate=${startDate}&endDate=${endDate}&current=${current}&pageSize=${pageSize}`,
        type: 'GET',
        success: function (result) {
            if(result.result=="Token過期請重新登錄"){
                login(localStorage.getItem("account"), localStorage.getItem("password"));
                status = getNewLogin(searchKey,startDate,endDate,current,pageSize)
            }else {
                if(result.result=="no permission"){
                    status.data = result.result
                }else {
                    status.data = result.result.map(item=>{
                        return (
                            {
                                key:item.ID,		//公告id
                                name:item.NAME,	//公告名
                                status:item.TOP_STATUS,		//置顶 ？true : false
                                createUser:item.CREATE_USER,
                                createTime:item.CREATE_DATE,
                                updateUser:item.UPDATE_USER,
                                updateTime:item.UPDATE_DATE,
                                new:item.ARTICLE_NEW
                            }
                        )
                    })
                    status.count = result.count
                }
            }
        },
        error:function (error) {
            status.data = "error"
            message.error("请求异常")
        }
    })
    return status;

}
